import React, { Component } from 'react';
import Link from 'next/link';
import Error from 'next/error'
// import fetch from 'isomorphic-unfetch';
import request from '../utils/request';
import _ from 'lodash';

export default class extends Component {
    static async getInitialProps({ res, query, err }) {
        const { page = 1 } = query || {};
        const statusCode = res ? res.statusCode : err ? err.statusCode : null;
        // const result = await fetch('http://47.106.111.213:3000/mock/32/btc/config/defines').then(r => r.json())
        const result = await request('http://47.106.111.213:3000/mock/32/btc/config/defines')
        return result.code === 0 ? { statusCode, payments: result.data.payments, page } : { page }
    }

    render () {
        const { payments = {}, page } = this.props;

        return (
            <div>
                Hello world
                {this.props.statusCode}
                <h3>支付方式1223</h3>
                <ul>
                    {
                        _.map(payments, (text, key) => {
                            return (
                                <li key={key}>{text}</li>
                            )
                        })
                    }
                </ul>
                <p>当前页码: <span>{page}</span></p>

                <Link prefetch href={{ pathname: '/about', query: { page: +page + 1 }}}><a>下一页</a></Link>
                <a href={`/about?page=${+page + 1}`}>洗衣额</a>
            </div>
        )
    }
}